package com.xc;

import com.xc.pattern.adapter.cls.ModuleAdapter;
import com.xc.pattern.adapter.cls.TargetModule;
import com.xc.pattern.birdge.color.BlueColor;
import com.xc.pattern.birdge.color.RedColor;
import com.xc.pattern.birdge.phone.ApplePhone;
import com.xc.pattern.birdge.phone.HWPhone;
import com.xc.pattern.builder.Computer;
import com.xc.pattern.builder.Director;
import com.xc.pattern.builder.HighComputerBuilder;
import com.xc.pattern.builder.LowerComputerBuilder;
import com.xc.pattern.chain.*;
import com.xc.pattern.command.*;
import com.xc.pattern.composite.File;
import com.xc.pattern.composite.Folder;
import com.xc.pattern.composite.Root;
import com.xc.pattern.decorator.BigBike;
import com.xc.pattern.decorator.Bike;
import com.xc.pattern.decorator.RSCBikeDecorator;
import com.xc.pattern.decorator.SuonaBikeDecorator;
import com.xc.pattern.facade.ImessageManager;
import com.xc.pattern.facade.MessageFacade;
import com.xc.pattern.factory.abstractFactory.FactoryProducer;
import com.xc.pattern.factory.abstractFactory.OrderFactory;
import com.xc.pattern.flyweight.CloudWebSite;
import com.xc.pattern.flyweight.Company;
import com.xc.pattern.flyweight.WebSiteFactory;
import com.xc.pattern.iterator.ICollection;
import com.xc.pattern.iterator.Iterator;
import com.xc.pattern.iterator.MyCollection;
import com.xc.pattern.memento.RoleOriginator;
import com.xc.pattern.memento.RoleStateCaretaker;
import com.xc.pattern.observe.*;
import com.xc.pattern.prototype.Person;
import com.xc.pattern.proxy.DigitalSell;
import com.xc.pattern.proxy.DigitalSellProxy;
import com.xc.pattern.proxy.DigitalSellReal;
import com.xc.pattern.state.NewOrderState;
import com.xc.pattern.state.OrderContext;
import com.xc.pattern.state.PayOrderState;
import com.xc.pattern.state.SendOrderState;
import com.xc.pattern.strategy.*;
import com.xc.pattern.template.AbstractProjectManager;
import com.xc.pattern.template.PayServiceProjectManager;
import com.xc.pattern.template.UserServiceProjectManager;

/**
 * @author xingchen
 * @description
 * @create 2022-08-16 21:55
 */
public class Main {

    public static void main(String[] args) {

        //region 单例设计模式
        //SingletonLazy.getInstanceSafe4().process();
        //SingletonHungry.getInstance().process();
        //endregion

        //region 简单工厂模式
        //Pay pay=SimplePayFactory.createPay("wechat pay");
        //Pay pay=SimplePayFactory.createPay("ali pay");
        //pay.unifiedOrder();
        //endregion

        //region 工厂方法模式
        //PayFactory aliPayFactory = new AliPayFactory();
        //Pay aliPay = aliPayFactory.getPay();
        //aliPay.unifiedOrder();
        //PayFactory wechatPayFactory = new WechatPayFactory();
        //Pay aliPay = wechatPayFactory.getPay();
        //aliPay.unifiedOrder();
        //endregion

        //region 抽象工厂模式
        //OrderFactory orderFactory = FactoryProducer.getFactory("ALI");
        //orderFactory.createPay().unifiedOrder();
        //orderFactory.createRefund().refund();
        //endregion

        //region 适配器模式(接口适配器)
        //Director director = new Director();
        //Computer lowComputer = director.create(new LowerComputerBuilder());
        //
        //Computer highComputer = director.create(new HighComputerBuilder());
        //
        //System.out.println(lowComputer.toString());
        //System.out.println(highComputer.toString());
        //endregion

        //region 适配器模式（类适配器）
        //TargetModule targetModule = new ModuleAdapter();
        //targetModule.methodA();
        //targetModule.methodB();
        //targetModule.methodC();
        //endregion

        //region 桥接模式
        //HWPhone blueHwPhone=new HWPhone(new BlueColor());
        //blueHwPhone.run();
        //
        //HWPhone redHwPhone=new HWPhone(new RedColor());
        //redHwPhone.run();
        //
        //ApplePhone blueApplePhone=new ApplePhone(new BlueColor());
        //blueApplePhone.run();
        //endregion

        //region 组合设计模式
        //创建根文件夹
        //Root root1=new Folder("C://");
        //
        ////建立子文件夹
        //Root desktop=new Folder("桌面");
        //Root myComputer=new Folder("我的电脑");
        ////建立子文件
        //Root javaFile=new File("HelloWor.java");
        //
        ////建立文件夹关系
        //root1.addFile(desktop);
        //root1.addFile(myComputer);
        ////建立文件关系
        //myComputer.addFile(javaFile);
        ////从0级开始展示，每下一级，多2条横线
        //root1.displayFile(0);
        //endregion

        //region 装饰器模式
        /**
         * 大自行车 200
         * 小自行车 100
         * 防爆胎 100
         * 喇叭 50
         */
        //选个自行车
        //Bike bike = new BigBike();
        //
        ////搭配两个  RSC防爆胎
        //bike = new RSCBikeDecorator(bike);
        //bike = new RSCBikeDecorator(bike);
        //
        ////搭配了一个喇叭
        //bike = new SuonaBikeDecorator(bike);
        //
        //System.out.println(bike.getDescription() + ",价格:" + bike.getPrice());

        //endregion

        //region 代理模式
        //真实对象
        //DigitalSell realObj =new DigitalSellReal();
        //realObj.sell();
        //
        ////代理对象
        //DigitalSell proxy=new DigitalSellProxy();
        //proxy.sell();

        //endregion

        //region 外观设计模式
        //ImessageManager imessageManager=new MessageFacade();
        //imessageManager.pushMessage();

        //endregion

        //region 享元设计模式
        //WebSiteFactory factory = new WebSiteFactory();
        //
        //CloudWebSite companySite1 = factory.getWebSiteByCategory("企业官网");
        //companySite1.run(new Company("精英科技"));
        //
        //CloudWebSite companySite2 = factory.getWebSiteByCategory("企业官网");
        //companySite2.run(new Company("精英信息"));
        //
        //
        //CloudWebSite byteDanceSite = factory.getWebSiteByCategory("信息流");
        //byteDanceSite.run(new Company("字节跳动"));
        //
        //CloudWebSite ucNews = factory.getWebSiteByCategory("信息流");
        //ucNews.run(new Company("优视科技"));
        //
        //System.out.println("网站分类总数：" + factory.getWebSiteCategorySize());
        //endregion

        //region 策略模式
        //简单订单对象
        //ProductOrder productOrder = new ProductOrder(800, 1, 33);
        //
        //PromotionContext context;
        //
        //double finalPrice;
        //
        ////没活动
        //context = new PromotionContext(new NormalActivity());
        //finalPrice = context.executeStrategy(productOrder);
        //System.out.println("NormalActivity = " + finalPrice);
        //
        ////折扣策略
        //context = new PromotionContext(new DiscountActivity(0.8));
        //finalPrice = context.executeStrategy(productOrder);
        //System.out.println("DiscountActivity = " + finalPrice);
        //
        ////优惠券抵扣
        //context = new PromotionContext(new VoucherActivity(100));
        //finalPrice = context.executeStrategy(productOrder);
        //System.out.println("VoucherActivity = " + finalPrice);

        //不同策略算出不同的活动价格

        //endregion

        //region 模板方法设计模式
        //AbstractProjectManager projectManager;
        //
        ////支付服务
        //projectManager = new PayServiceProjectManager();
        //
        //projectManager.processProject();
        //System.out.println("=================");
        ////用户服务
        //projectManager = new UserServiceProjectManager();
        //
        //projectManager.processProject();

        //endregion

        //region 观察者设计模式

        //创建一个主题  此处是老板
        //BossConcreteSubject subject=new BossConcreteSubject();
        ////创建观察者，即摸鱼的同事
        //Observer AObserver=new StaffAConcreteObserver();
        ////创建观察者，即摸鱼的同事
        //Observer BObserver=new StaffBConcreteObserver();
        ////建立对应的关系，老板这个主题被同事进行观察
        //subject.addObserver(AObserver);
        //subject.addObserver(BObserver);
        ////主题开始活动，里面会通知观察者（相当于发布消息）
        //subject.doSomething();

        //endregion

        //region 责任链设计模式
        //RiskControlManager firstControlManager = new FirstRiskControlManager("初级风控");
        //
        //RiskControlManager secondControlManager = new SecondRiskControlManager("中级风控");
        //
        //RiskControlManager thirdControlManager = new ThirdRiskControlManager("高级风控");
        //
        ////形成调用链
        //firstControlManager.setSuperior(secondControlManager);
        //secondControlManager.setSuperior(thirdControlManager);
        //
        //ChainRequest request1 = new ChainRequest();
        //request1.setRequestType(ChainRequestType.TRANSFER.name());
        //request1.setMoney(22000);
        //firstControlManager.handlerRequest(request1);
        //endregion

        //region 命令设计模式

        //创建接收者，空调就是接收者
        //ConditionReceiver receiver = new ConditionReceiver();
        //
        ////创建命令对象，设置命令的接收者
        //Command onCommand = new OnCommand(receiver);
        //Command offCommand = new OffCommand(receiver);
        //Command coolCommand = new CoolCommand(receiver);
        //Command warmCommand = new WarmCommand(receiver);
        //
        ////创建请求者，把命令对象设置进行，app就是请求发起者
        //AppInvoker appInvoker = new AppInvoker();
        //appInvoker.setOnCommand(onCommand);
        //appInvoker.setOffCommand(offCommand);
        //appInvoker.setCoolCommand(coolCommand);
        //appInvoker.setWarmCommand(warmCommand);
        //
        //appInvoker.on();
        //System.out.println();
        //
        //appInvoker.cool();
        //System.out.println();
        //
        //appInvoker.warm();
        //System.out.println();
        //
        //appInvoker.off();

        //endregion

        //region 迭代器设计模式

        //ICollection collection = new MyCollection();
        //collection.add("小星A");
        //collection.add("小星C");
        //collection.add("小星D");
        //collection.add("小星E");
        //collection.add("小星F");
        //
        //Iterator iterator = collection.iterator();
        //while (iterator.hasNext()) {
        //    Object obj = iterator.next();
        //    System.out.println(obj);
        //}

        //endregion

        //region 备忘录设计模式
        //RoleOriginator role = new RoleOriginator();
        //role.display();
        //role.fight();
        //role.display();
        //System.out.println("保存上面的快照");
        //RoleStateCaretaker caretaker = new RoleStateCaretaker();
        //caretaker.setMemento(role.saveState());
        //
        //role.fight();
        //role.fight();
        //role.fight();
        //role.display();
        //
        //System.out.println("恢复快照");
        //role.recovery(caretaker.getMemento());
        //role.display();

        //endregion

        //region 状态设计模式
        OrderContext orderContext=new OrderContext();
        orderContext.setState(new NewOrderState());

        orderContext.setState(new PayOrderState());

        orderContext.setState(new SendOrderState());
        //endregion

    }
}
